<template>
  <div>
    <el-dialog
      title="用药情况"
      :visible.sync="addDiavisible"
      width="50%"
      @close="cancel"
      @opened="beforeopen"
    >
      <el-form
        ref="formRef"
        :rules="formRules"
        :model="form"
        label-width="110px"
      >

        <el-form-item label="药物名称" prop="coronaryIndex">
          <el-select
            v-model="form.coronaryIndex"
            clearable
            @change="seChange"
            style="width: 100%"
          >
            <el-option
              v-for="item in coronaryIndex"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用法用量" prop="diseaseTime" style="text-align: left">
          <el-row>
            <el-col :lg="2" :xl="2" >每日</el-col>
            <el-col :lg="6" :xl="6">
              <el-input v-model="form.coronaryEveryday"></el-input>
            </el-col>
            <el-col :lg="2" :xl="2">次</el-col>

            <el-col :lg="3" :xl="3" style="margin-left: 30px">每次</el-col>

            <el-col :lg="6" :xl="6">
              <el-input v-model="form.coronaryEveryTime"></el-input>
            </el-col>

          </el-row>
        </el-form-item>





      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="addSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { inputValidator, selectValidator } from "@/utils/validate";
export default {
  data() {
    return {
      addDiavisible: false,
      form: {
        insulinName:"",
        insulinIndex:"",
        coronaryName: "",
        coronaryIndex: "",
        coronaryEveryday: "",
        coronaryEveryTime: "",
      },
      coronaryIndex: [
        { id: 1, name: "高血压" },
        { id: 2, name: "糖尿病" },
        { id: 3, name: "冠心病" },
        { id: 4, name: "慢性阻塞性肺疾病" },
        { id: 5, name: "恶性肿瘤" },
        { id: 6, name: "脑卒中" },
        { id: 7, name: "严重精神障碍" },
        { id: 8, name: "结核病" },
        { id: 9, name: "肝炎" },
        { id: 10, name: "其他法定传染病" },
        { id: 11, name: "职业病" },
        { id: 12, name: "其他" },
      ],
      insulinIndex: [
        { id: 1, name: "是" },
        { id: 2, name: "否" },

      ],
      formRules: {
        // medicineIndex: selectValidator,
      },
    };
  },
  created() {},
  methods: {
    //关闭
    cancel() {
      for (let key in this.form) {
        this.form[key] = "";
      }
      this.addDiavisible = false;
    },
    beforeopen() {
      this.$refs.formRef.clearValidate();
    },
    //提交
    addSubmit() {
      this.$refs.formRef.validate((valid) => {
        this.$emit("transData", this.form);
        this.cancel();
      });
    },
    //供父组件调用函数
    openDialog() {
      this.addDiavisible = true;
    },
    seChange(value) {
      this.coronaryIndex.forEach((e) => {
        if (e.id == value) {
          this.form.coronaryName = e.name;

        }
      });
    },


    seChangecoronary(value) {
      this.insulinIndex.forEach((e) => {
        if (e.id == value) {
          this.form.insulinName = e.name;

        }
      });
    },
    monthChange(month){
      return month+1
    }
  },
};
</script>
